import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate' // 引入
import detial from './modules/detial'
import cart from './modules/cart'
import user from './modules/user'
Vue.use(Vuex)

export default new Vuex.Store({
  plugins: [createPersistedState({ // 在插件中引入
    reducer (data) { // 约定需要持久化的数据，如果不约定，只引入插件， 会把所有state状态持久化
      return {
        shoppingCart: data.cart, // 约定 city module中的city数据持久化
        user:data.user
      }
    }
  })],
  // plugins: [createPersistedState()],
  state: {
    foo: true,
    isHomeShow: true
  },
  mutations: {
    show(state){
      state.foo = true

    },
    hide(state){
      state.foo = false
      state.isHomeShow = false
    },
    ishow (state) {
      state.isHomeShow = true
    },
    ishide (state) {
      state.isHomeShow = false
    }
  },
  actions: {
  },
  modules: {
    detial,
    cart,
    user
  }
})
